
# 3、练习单继承，多重继承案例（和上课保持一致即可）
#单继承，属性super父类的，会完全跟着父类。方法super父类的，不会影响子类本身方法的生效
class Animal:
    def __init__(self, name):
        self.name = name +'bbq'

    def run(self):
        print('pao,kan')

    def eat(self):
        print('chi ')

    def sleep(self):
        print('shui')

class Dog(Animal):
    def __init__(self,name,colour):
        super().__init__(name)
        self.colour = colour + 'xyz'
    def bark(self):
        print(f'{self.name}汪汪叫  ,颜色 is {self.colour}')

    def run(self):
        print( f'{self.name}快乐的玩耍')

class Cat(Animal):
    def catch(self):
        print('wanqiu')
    def run(self):
        super().run()
        print(f"cat正在乱跑")

class XiaoTQ(Dog):
    def __init__(self,name,colour,age):
        super().__init__(name,colour)
        self.age =age
    def fly(self):
        print(f'{self.name}xiu~一下飞走了,颜色是{self.colour},nianling is {self.age} ')

#多继承
#可以用__mro__查看参数传递顺序。使用super,使用父类的属性定义，继承按顺序进行..从最底层传参，super之后，传入的参数按父类中属性定义运算

class Parent:
    def __init__(self,height):
        self.height = height

class Son1(Parent):
    def __init__(self,age,*args):
        self.age =age -5
        super().__init__(*args)

class Son2(Parent):
    def __init__(self,score,*args):
        self.score = score +10
        super().__init__(*args)

class GrandSon(Son1,Son2):
    def __init__(self,name,*args):
        self.name = name
        self.score = 0   #super之后，被Son2的score属性覆盖了
        super().__init__(*args)

    def print(self):
        # print(self.name,'小明的年龄是'+str(self.age),'小明的成绩是'+str(self.score))

        print(f'这是今天的主角{self.name}，他今年{self.age}岁,他的期末成绩考了{self.score}分，他的身高有{self.height}cm')

#多态
class Person:
    def __init__(self,name):
        self.name = name

    def run_with_animal(self,animal:Animal):
        print(f'{self.name}想和其他小动物玩')

        animal.run()

if __name__ == '__main__':
    dahuang =Dog('dahuang','red')
    XTQ =XiaoTQ('啸天','black',2000)
    XM =Cat('helloket')
    dahuang.bark()
    XTQ.fly()
    XM.run()
    print("#"*50)
    xiaoming = GrandSon('xiaoming',12,95,175)
    xiaoming.print()
    print("#" * 50)
    zhangsan =Person('zhangsan')
    # zhangsan.run_with_animal(dahuang)
    zhangsan.run_with_animal(XM)

